using System;
using System.Collections.Generic;
using System.Text;

namespace JTest
{
    class Utils
    {
        /// <summary>
        /// Ham tao ra mang random cac gia tri so nguyen trong mot khoang
        /// </summary>
        /// <param name="begin">kieu ulong, nguong bat dau</param>
        /// <param name="end">kieu ulong, nguong ket thuc</param>
        /// <returns>kieu ulong[], mang cac gia tri random</returns>
        public static uint[] getRandomIntegerListInValueRange(uint begin, uint end)
        {
            //tao mang gia tri tu begin den end
            uint[] ids = new uint[end - begin + 1];
            uint temp = begin;
            uint index = 0;
            while (temp <= end)
            {
                ids[index] = temp;
                temp++;
                index++;
            }
            //tron ngau nhien cac phan tu
            uint[] reIds = (uint[])ids.Clone();

            Random random = new Random();
            for (int i = 0; i < ids.Length; i++)
            {
                int swapIndex = random.Next(i, ids.Length);
                if (swapIndex != i)
                {
                    temp = reIds[i];
                    reIds[i] = reIds[swapIndex];
                    reIds[swapIndex] = temp;
                }
            }
            return reIds;
        }

        /// <summary>
        /// Ham tao mang so nguyen ngau nhien co gia tri tu 0 den length
        /// </summary>
        /// <param name="length">kieu int, chieu dai mang</param>
        /// <returns>mang int[]</returns>
        public static int[] getRandomIntegerList(int length)
        {
             //tao mang gia tri tu begin den end
            int[] ids = new int[length];
            int index = 0;
            while (index < length)
            {
                ids[index] = index;
                index++;
            }
            //tron ngau nhien cac phan tu
            int[] reIds = (int[])ids.Clone();

            Random random = new Random();
            for (int i = 0; i < ids.Length; i++)
            {
                int swapIndex = random.Next(i, ids.Length);
                if (swapIndex != i)
                {
                    int temp = reIds[i];
                    reIds[i] = reIds[swapIndex];
                    reIds[swapIndex] = temp;
                }
            }
            return reIds;
        }
    }
}
